#include <QMouseEvent>

#include "cell.h"
#include "global_config.h"


Cell::Cell(QWidget *parent) :
    QLabel(parent)
{
    showImage();
}

void Cell::showImage()
{
    QString imgPath = ":/images/";

    if (isOpened()) {
        if (openedByWho_ == Cell::ME) {
            imgPath += "blue";
        } else if (openedByWho_ == Cell::OPPONENT) {
            imgPath += "red";
        } else if (openedByWho_ == Cell::SYSTEM) {
            imgPath += "yellow";
        }
        if (isBomb()) {
            imgPath += "Bomb";
        } else {
            imgPath += QString::number(bombsAround());
        }
    } else {
        if (state_ == Cell::ORIGINAL) {
            imgPath += "original";
        } else if (state_ == Cell::FLAGED) {
            imgPath += "flag";
        } else if (state_ == Cell::QUESTIONED){
            imgPath += "question";
        } else if (state_ == Cell::HIGHLIGHTED) {
            imgPath += "highlight";
        }
    }
    imgPath += ".png";

    image_ = QPixmap(imgPath);
    image_ = image_.scaled(gMineSweeperCellPixSize - 1, gMineSweeperCellPixSize - 1);

    setPixmap(image_);
    resize(gMineSweeperCellPixSize, gMineSweeperCellPixSize);
    show();
}

bool Cell::isBomb() const
{
    return isBomb_;
}

void Cell::setIsBomb(bool newIsBomb)
{
    isBomb_ = newIsBomb;
}

bool Cell::isOpened() const
{
    return isOpened_;
}

void Cell::setIsOpened(bool newIsOpened)
{
    isOpened_ = newIsOpened;
}

uint8_t Cell::openedByWho() const
{
    return openedByWho_;
}

void Cell::setOpenedByWho(uint8_t newOpenedByWho)
{
    openedByWho_ = newOpenedByWho;
}

uint8_t Cell::state() const
{
    return state_;
}

void Cell::setState(uint8_t newState)
{
    state_ = newState;
}

uint32_t Cell::bombsAround() const
{
    return bombsAround_;
}

void Cell::setBombsAround(uint32_t newBombsAround)
{
    bombsAround_ = newBombsAround;
}

